/**
 * Copyright(c) Hainan eKing Technology co., LTD
 *
 * @date 2013年8月13日
 * 	
 * Original Author: 郑兴(zhengxing)
 *
 * ChangeLog
 *
 */
package com.hnas.sys.dao;

import java.util.List;

import javax.persistence.Query;

import org.springframework.stereotype.Component;

import com.hnas.core.dao.BaseDaoImpl;
import com.hnas.sys.orm.Authority;

/**
 * @author 郑兴(zhengxing)
 *
 */
@Component("authorityDAO")
public class AuthorityDAOImpl extends BaseDaoImpl<Authority> implements AuthorityDAO {
	public AuthorityDAOImpl() {
		super(Authority.class);
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.hna.dt.dao.system.AuthorityDAO#loadAll()
	 */
	@SuppressWarnings("unchecked")
	public List<Authority> loadAll() {
		Query query = entityManager.createQuery("From Authority r where r.statusStr='VALID' order by id");
		return query.getResultList();
	}

	public List<Authority> getAllAuthorities() {
		Query query = entityManager.createQuery("FROM Authority  r where r.statusStr='VALID' order by id");
		return query.getResultList();
	}
	/*
	 * (non-Javadoc)
	 * @see com.hna.dt.dao.system.AuthorityDAO#loadAuthorityByName(java.lang.String)
	 */
	public Authority loadAuthorityByName(String AuthorityName) {
		String query = "From Authority a where a.name=?1 and a.statusStr='VALID'";
		List<Authority> ls = this.findByQuery(query, AuthorityName);
		if (null != ls && ls.size()>0)
			return ls.get(0);
		return null;
	}
}
